{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xml.etree.cElementTree as et \n",
    "import pandas as pd\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['1376', '622', '1544', '660', '1', '633', '538', '748', '606', '1']\n"
     ]
    }
   ],
   "source": [
    "xml_tree = et.ElementTree(file='./label/Cam_2_15_12-13_13-12-14.xml')  # 文件路径\n",
    "root = xml_tree.getroot();\n",
    "b_box = []\n",
    "for node in root:\n",
    "    if node.tag == \"object\":\n",
    "        for sub_node in node:\n",
    "            if sub_node.tag == \"bndbox\":\n",
    "                for box in sub_node:\n",
    "                    b_box += [box.text]\n",
    "                b_box += \"1\"\n",
    "print(b_box)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open(\"C:/Users/ZZK/TF-object_detection/shoes/data.txt\",\"w\")\n",
    "path = \"C:/Users/ZZK/TF-object_detection/shoes/yijiao\"\n",
    "fileList = os.listdir(path)\n",
    "for file in fileList:\n",
    "    f.write(\"C:/Users/ZZK/TF-object_detection/shoes/yijiao/\"+file+\" \")\n",
    "    xml_file,_ = file.split(\".\")\n",
    "    xml_tree = et.ElementTree(file='./label/'+xml_file+\".xml\") \n",
    "    root = xml_tree.getroot();\n",
    "    for node in root:\n",
    "        if node.tag == \"object\":\n",
    "            for sub_node in node:\n",
    "                if sub_node.tag == \"bndbox\":\n",
    "                    for box in sub_node:\n",
    "                        f.write(box.text+\",\")\n",
    "                    f.write(\"1 \")\n",
    "    f.write(\"\\n\")\n",
    "    \n",
    "f.close()   "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
